#!/usr/bin/env python
# -*- coding: utf-8 -*-

# @Time     :2020/12/20
# @Author   :Changshu
# @File     :Exercise_605.py

# 605. 种花问题
# 假设你有一个很长的花坛，一部分地块种植了花，另一部分却没有。可是，花卉不能种植在相邻的地块上，它们会争夺水源，两者都会死去。

class Solution:
	def canPlaceFlowers(self, flowerbed: list, n: int) -> bool:
		count=0
		for i in range(len(flowerbed)):
			f=flowerbed[i]
			if f==0 and (i==0 or flowerbed[i-1]==0) and (i==len(flowerbed)-1 or flowerbed[i+1]==0):
				flowerbed[i]=1
				count+=1
		if count>=n:
			return True
		return False

if __name__ == '__main__':
	solution=Solution()
	# flowerbed=[1,0,0,0,1]
	# n=2
	# flowerbed = []
	# n=1
	flowerbed = [1,0,0,0,0,1]
	n=2
	print(solution.canPlaceFlowers(flowerbed,n))